// pages/fwform/fwform.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

    point: "",
    building: "",
    room: "",
    name: "",
    gender: "",
    mobile: "",
    idcardFrontUrl: "",
    idcardBackUrl: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    this.setData({
      point: options.title
    })
  },
  async uploadPicture1() {
    const media = await wx.chooseMedia({
      count: 1,
      mediaType: ["image"],
      sizeType: ["compressed"]
    })
    console.log(media.tempFiles[0].tempFilePath)
    wx.uploadFile({
      url: wx.http.baseURL + '/upload',
      filePath: media.tempFiles[0].tempFilePath,
      name: 'file',
      header: {
        Authorization: app.token
      },
      formData: {

      },
      success: (res) => {
        console.log(res)
        const data = JSON.parse(res.data);
        this.setData({

          idcardBackUrl: data.data.url
        })
      }
    })

  },
  async uploadPicture(e) {
    const media = await wx.chooseMedia({
      count: 1,
      mediaType: ["image"],
      sizeType: ["compressed"]
    })
    console.log(media.tempFiles[0].tempFilePath)
    wx.uploadFile({
      url: wx.http.baseURL + '/upload',
      filePath: media.tempFiles[0].tempFilePath,
      name: 'file',
      header: {
        Authorization: app.token
      },
      formData: {

      },
      success: (res) => {
        console.log(res)
        const data = JSON.parse(res.data);
        this.setData({

          idcardFrontUrl: data.data.url
        })
      }
    })

  },
  removePicture() {
    console.log(123333)
    this.setData({
      idcardFrontUrl: ""

    })
  },
  removePicture1() {
    this.setData({
      idcardBackUrl: ""

    })

  },
  input(e){
    console.log(e)
  },
 async addfw() {
   console.log(this.data.mobile)

   delete this.data.__webviewId__
const res=await wx.http({
  url:"/room",
  method:"post",
  data:this.data
})
console.log(res)
if(res.code == 10000){
  wx.navigateTo({
    url: '/pages/wdfw/wdfw',
  })
}
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})